#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename	:  authentication-hdzx.sh
# Version	:  1.0
# Date		:  2020/05/21
# Author	:  Lz
# Email		:  lz843723683@gmail.com
# History	:     
#             Version 1.0, 2020/05/21
# Function	： 测试华电众信-身份鉴别失败处理
# Out		:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

## TODO : 测试收尾清除工作
#
AUTHENClean_FTHDZX(){
	return $TPASS
}


## TODO: 调用程序退出函数
#    In: $1 => 调用脚本结果值
AUTHENExit_FTHDZX(){
        # 调用退出函数，其中调用了clean相关函数
	Exit_FTLIB ${1}
}


## TODO: 用户界面
#
AUTHENUSAGE_FTHDZX(){
	USAGE_FTLIB "华电众信测试 - 身份鉴别失败处理"
}


## TODO : 测试前的初始化 
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other=> TCONF
AUTHENInit_FTHDZX(){
        # 调用初始化函数
	Init_FTLIB "AUTHENClean_FTHDZX"
        # 调用用户界面函数
 	AUTHENUSAGE_FTHDZX
}


## TODO ：身份鉴别失败处理
#
AUTHENTest01_FTHDZX(){
	# 配置文件
	local filearr=(/etc/pam.d/sshd /etc/pam.d/login)
	# 开头标示
	local flag="pam_tally2.so"
	# 锁定时间
        local unlock="unlock_time=600"
	# 锁定次数
	local deny="deny=5"

	local ret="TPASS"
	local file=""
	# 判断是否存在变量
	for file in ${filearr[@]}
	do	
		echo "cat ${file} : "
		cat ${file} | grep ${flag}
		cat ${file} | grep ${flag} | grep ${unlock} | grep -q ${deny}
		ret=$?
		if [ $ret -ne 0 ];then
			echo "未找到配置 ${tmout}"
			OutputRet_FTLIB ${TFAIL}
		        RetParse_FTLIB "$file 要求密码输错 ${deny} 次.锁定 ${unlock}s" "False"
		else
			OutputRet_FTLIB ${TPASS}
		        RetParse_FTLIB "$file 要求密码输错 ${deny} 次.锁定 ${unlock}s" "False"
		fi
	done
}


## TODO : Main
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other => TCONF
AUTHENMain_FTHDZX(){
	AUTHENInit_FTHDZX

	AUTHENTest01_FTHDZX

	return ${TPASS}	
}

AUTHENMain_FTHDZX
AUTHENExit_FTHDZX $?
